import time
import os
import sys

class Logger(object):
    def __init__(self, root_path, stream=sys.stdout):
        '''
        :param root_path: 输出日志路径
        '''
        output_dir = os.path.join(root_path, 'print_logs')
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)
            
        log_name = '{}.log'.format(time.strftime('%Y-%m-%d-%H-%M'))
        file_name = os.path.join(output_dir, log_name)
        self.terminal = stream
        self.log = open(file_name, "a")

    def write(self, message):
        # self.terminal.write(message)
        self.log.write(message)  # 将print的结果存储到log日志中

    def flush(self):
        pass